<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>
	</head>
	<body>
		<input id="t1" type="text">
		<input type="button" value="添加" onclick="fn1(1)">
		<input type="button" value="插入" onclick="fn1(2)">
		<input type="button" value="删除" onclick="fn1(3)">
		<ul id="myul">
			<li>北京</li>
			<li id="sh">上海</li>
			<li>广州</li>
		</ul>
		
		
		<script type="text/javascript">
			function fn1(x){
				switch(x){
				case 1:
					var d = document.createElement("li");
					d.innerText = t1.value;
					myul.appendChild(d);
					break;
				case 2:
					var d = document.createElement("li");
					d.innerText = t1.value;
					myul.insertBefore(d,sh);
					break;
				case 3:
					myul.removeChild(sh);
					break;
				}
				
			}
			
		</script>
	</body>
</html>